import axios from 'axios'
import store from '@/store'
export function request(config) {

  // return new Promise((resolve,reject)=>{
  //   const instance = axios.create({
  //     baseURL: 'http://localhost:8080',
  //     timeout: 5000
  //   })
  //   instance(config).then(res => {
  //     //console.log(res)
  //     resolve(res)
  //   }).catch(err=>{
  //     //console.log(err)
  //     reject(err)
  //   })
  // })
	
  const instance = axios.create({
		// baseURL: 'http://localhost:8080/boot-launch-1.0.0',
      baseURL: 'http://localhost:8088',
			// baseURL: 'http://139.155.89.3:8080/boot-launch-1.0.0',
			// method:'post',
      timeout: 5000
    })
		instance.interceptors.request.use(data=>{
			let authorization=window.localStorage.getItem('authorization')
			let uid=window.localStorage.getItem('uid')
			if (authorization!=null&&uid!=null) {
				data.headers.authorization = authorization;
				data.headers.uid = uid;
			}
			return data
		})
		instance.interceptors.response.use(
		  response => {
		    //拦截响应，做统一处理 
				// console.log(response.headers)
				// console.log(store.state)
				if(response.data==""&&response.headers.login=='bad'){
				 // console.log("saddsadas")
				store.commit("updateLogin",true)
				//return response
		    }
				else{					
					return response
				}
		  })
		
  return instance(config)
}
